home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
INFO
/
PCCDEMO.ZIP
/
COMP1.EXE
/
ASSEMBLY.PRS
< prev
next >
Wrap
Text File
|
1993-12-20
|
9KB
|
140 lines
ÇÆÆäîüïÿ ïÇìåöÇåä àÄæ ÅæÄåæÇîîäæÆ ╬╠╧╧╬╠╬╠╬╠╬╠╡
│ ∩α±≤ ¢: ≤ τ Σ Γ ∩ ⌠
│
▄ ▄ │ In this first article I will
▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄▄▄ █▄▄ █ ▄ ▄ │ attempt to introduce the basic
▄▄█ █▄▄ █▄▄ █▄█ █ █ █ █ █ █ █ █ │ concepts of assembly language
█▄█ ▄▄█ ▄▄█ █▄▄ █ █ █ █▄█ █ █▄█ │ programming. If you have no
▄▄█ │ knowledge of assembly language,
σ ε ± ∩ ± ε µ ± α ∞ ∞ Σ ± ≥ │ you may find this article
│ fairly heavy-going, but if you
│ stick with it, things should
│ become easier later on.
ß√ ≤εß√ µ±α√ │
│ Since assembly language is
≤τΦ≥ ≥Σ±ΦΣ≥ εσ α±≤ΦΓδΣ≥ Φ≥ │ really a CPU-level programming
αΦ∞Σπ ∞αΦφδ√ α≤ Γ αφπ ∩α≥Γαδ │ language, it seems logical to
∩±εµ±α∞∞Σ±≥ ÷τε ÷αφ≤ ≤ε δΣα±φ │ begin with a quick tour of
τε÷ ≤ε ∩±εµ±α∞ Φφ α≥≥Σ∞ßδ√ │ the CPU itself. The lowest
δαφµ⌠αµΣ. │ common denominator of the Intel
│ 80x86 family of processors used
│ in all IBM-compatible machines
is the 8086, so that is the CPU │ more quickly than memory
we will be looking at. │ which is outside the CPU.
Note that all the following │
information applies to all │ 2. The execution unit. This
80x86 processors when they are │ is the part of the CPU which
running in real mode. DOS runs │ actually performs computations.
in real mode, so programs │ The registers are contained
written to run under DOS │ inside the execution unit.
will be running in real mode │
too. │ 3. The bus interface unit.
│ The CPU is connected to the
From the programmer's point │ outside world via this unit. All
of view, the CPU can be split │ data entering and leaving the
into three logical units as │ CPU travels through the bus
follows: │ interface unit.
│ Of course, the CPU is a far
1. The registers. These │ more complex piece of hardware
are storage locations inside │ than this simple breakdown
the CPU, analogous to RAM. │ might suggest, but for the
Registers can be accessed much │ purpose of this article we only
need to worry about the above │ looking at these registers here.
three units. I will now discuss │
each of the three units in more │ On an 8086, all registers are
detail. │ 16 bits wide. This means that
│ they can hold unsigned values
│ from 0 to 65,535 (0 to FFFF hex),
ôçä æäåêÆôäæÆ │ or signed values from -32,768 to
│ 32,767 (8000 to 7FFF hex). The
The 8086 register set can be │ upper and lower 8 bits of
sub-divided into three classes: │ some registers can be accessed
general registers, segment │ separately. Each 8-bit "sub-
registers, and status registers. │ register" can hold an unsigned
These three classes of │ value from 0 to 255 (0 to FF hex)
registers make up the base │ or a signed value from -128 to
register set common to all │ 127 (80 to 7F hex). The 80386
80x86 processors. The more │ (and its successors) have some
complex CPUs also have protection │ 32-bit registers, but these are
registers, control registers, │ usually just used as 16-bit
test registers and debug │ registers when running under DOS.
registers, but I will not be │
≤τΣ µΣφΣ±αδ ±ΣµΦ≥≤Σ±≥ │ on. Some of the general
│ registers, particularly SP,
In some ways, the general │ have special uses which I will
registers are similar to │ discuss later.
variables in high-level │
languages. Like variables, they │ ≤τΣ ≥Σµ∞Σφ≤ ±ΣµΦ≥≤Σ±≥
are used to store data while │
the program is working on that │ Whenever you need to address
data. Unlike variables, the │ memory on an 8086, you actually
size and number of general │ use two addresses. This is
registers is strictly limited. │ because the execution unit only
The basic general registers are │ works with 16 bit numbers,
known as AX, BX, CX, DX, SI, DI │ while memory addresses are 20
, SP and BP. It is possible to │ bits wide, allowing up to 1
access the first four (AX, BX, CX │ megabyte of memory to be
and DX) in two separate 8-bit │ accessed by the CPU (later
alves. The upper 8 bits of AX are │ processors have even more bits
collectively known as AH, and │ in their addresses, allowing
the low 8 bits are AL. BX is │ access to more memory). The
split into BH and BL, and so │ first address, called the
offset, is specified in a │ the instruction pointer, IP.
general register or directly │ This register, along with the
("immediately") in the │ segment register called CS,
instruction which is accessing │ always points at the next
memory. The second address, │ instruction to be executed, and
the segment, is always │ is used to fetch each instruction
specified by the contents │ in turn from memory so that it
of one of the segment │ can be executed. The other status
registers. You may be wondering │ register is called FLAGS.
how two 16-bit registers can make │ Every time the CPU performs
a 20-bit address, but you'll have │ an arithmetic operation, some of
to wait until I get around to │ the bits in FLAGS are updated to
taking a closer look at memory │ reflect the outcome of the
addressing for the answer. │ operation. Some of the flags are:
│ CF, the carry flag, which
≤τΣ ≥≤α≤⌠≥ ±ΣµΦ≥≤Σ±≥ │ indicates (among other things)
│ that the result of an
There are only two registers │ addition/subtraction was too
in this class, so I'll look at │ big/small to fit into the number
each one separately. Firstly, │ of bits allocated for it; PF, the
parity flag, which is set to 1 │ retrieved from memory or I/O
whenever the result an arithmetic │ (input/output) ports.
operation has an even number of │
bits set to 1; ZF, the zero flag, │
which is set to one whenever the │ ôçä üöÆ êìôäæàÇéä öìêô
result of an arithmetic operation │
is zero. │ This unit connects the CPU to
│ all external devices, including
│ memory. Whenever an instruction
ôçä äùäéöôêÄì öìêô │ needs data from memory or an I/O
│ port, it is the BIU that is
The execution unit contains │ responsible for fetching that
the entire register set, as well │ data. Similarly, the BIU handles
as the arithmetic/logic unit │ all outgoing data from the CPU to
(ALU). This unit performs all │ memory or I/O ports.
computations necessary to │
complete all instructions. The │
execution unit communicates with │ Well, that completes our brief
the bus interface unit whenever │ tour of the CPU. In the next
data needs to be sent to or │ article, I will introduce the
basic structure of a simple │
assembly language program, and │
discuss the procedure for │
creating an executable file from │
your source code ñ │